1. Field of the Invention
The present invention relates to garbage collection within computer memory. More specifically, the present invention relates to a method and an apparatus to facilitate testing of garbage collection implementations within a computer memory.
2. Related Art
Many modern computing systems and languages rely upon garbage collectors to reclaim unused storage. A garbage collector relieves the programmer from the task of deallocating storage that is no longer needed for the execution of a program, and thereby makes more efficient use of the memory within the computing system.
While garbage collectors are desired within these computing systems, the garbage collector is frequently one of the largest, and most complex, software modules in the computing system. Errors in the garbage collector, however, may be very difficult to detect because these errors can manifest themselves in other program code that may be executed long after the garbage collector performs the erroneous actions that give rise to the errors. This delay between error occurrence and error manifestation makes debugging and testing garbage collectors a very difficult task. Additionally, errors within a platform-independent virtual machine, or in computer code executing on the platform-independent virtual machine, may cause errors that appear to originate within the garbage collector, thereby causing debugging efforts to be incorrectly allocated.
An additional problem with debugging a garbage collector is that a particular error may manifest itself differently, or in different places in the platform-independent virtual machine. The way an error manifests itself can depend upon non-deterministic factors such as which programs are running on the platform-independent virtual machine or differences in program execution speed caused by non-deterministic interactions with external resources.
What is needed is a method and an apparatus that facilitates testing a garbage collection implementation while eliminating the problems described above.
One embodiment of the present invention provides a system to facilitate testing of garbage collection implementations. The system operates by first receiving a trace of valid memory transactions at a test harness. This trace of valid memory transactions is replayed through the test harness into a memory manager, which includes a garbage collection implementation under test. The results of replaying this trace are then observed to verify that the garbage collection implementation under test does not erroneously change the contents of the memory.
In one embodiment of the present invention, the trace of valid memory transactions includes memory transactions associated with multiple platform-independent computer programs concurrently executing on a platform-independent virtual machine.
In one embodiment of the present invention, the test harness includes an interface for each entry point into the memory manager.
In one embodiment of the present invention, a second garbage collection implementation under test is substituted for the garbage collection implementation under test.
In one embodiment of the present invention, verifying that the garbage collection implementation under test does not incorrectly change the content of the memory includes comparing the current state of the memory with the recorded state of memory stored with the trace of valid memory transactions.
In one embodiment of the present invention, the trace of valid memory transactions is gathered using a tracing platform-independent virtual machine.
In one embodiment of the present invention, the tracing platform-independent virtual machine is known to operate correctly.